package com.molyfun.parents.activity.ask.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/18/16.
 */
public class MultChooseBarView extends LinearLayout implements View.OnClickListener {

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.edit)
    TextView mEdit;
    @InjectView(R.id.edit_layout)
    LinearLayout mEditLayout;

    @InjectView(R.id.operation)
    TextView mOperation;
    @InjectView(R.id.choose_all)
    TextView mChooseAll;
    @InjectView(R.id.cancel)
    TextView mCancel;


    public MultChooseBarView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public MultChooseBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public MultChooseBarView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_multchoose_bar, this);
        ButterKnife.inject(this);
        mOperation.setOnClickListener(this);
        mChooseAll.setOnClickListener(this);
        mCancel.setOnClickListener(this);
        mEdit.setOnClickListener(this);
    }

    public void reset(){
        mEdit.setVisibility(View.VISIBLE);
        mEditLayout.setVisibility(View.GONE);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.edit:
                mEdit.setVisibility(View.GONE);
                mEditLayout.setVisibility(View.VISIBLE);
                if (mMultChooseCallback != null) {
                    mMultChooseCallback.onEditBegin();
                }
                break;

            case R.id.operation:
                if (mMultChooseCallback != null) {
                    mMultChooseCallback.onOperationClick();
                }
                break;
            case R.id.choose_all:
                if (mMultChooseCallback != null) {
                    mMultChooseCallback.onAllChoose();
                }
                break;
            case R.id.cancel:
                if (mMultChooseCallback != null) {
                    mMultChooseCallback.onCancel();
                }
                mEdit.setVisibility(View.VISIBLE);
                mEditLayout.setVisibility(View.GONE);
                break;
        }
    }

    public void setMultChooseCallback(MultChooseCallback multChooseCallback) {
        this.mMultChooseCallback = multChooseCallback;
    }

    private MultChooseCallback mMultChooseCallback;

    public interface MultChooseCallback {

        void onEditBegin();
        //choose all
        public void onAllChoose();

        //cancel choose all
        public void onCancel();

        /**
         * on confirm button click
         */
        public void onOperationClick();
    }

}